<template>
  <div>
    <el-dialog
      :visible.sync="tableShow"
      @close="handleClickDeal('cancel')"
      :modal-append-to-body="false"
      :close-on-click-modal="false"
      title="任务监听器"
      append-to-body
      width="35%"
    >
      <el-form :model="form" label-width="90px" size="small">
        <el-form-item label="事件类型">
          <el-select v-model="form.event" placeholder="请选择">
            <el-option
              v-for="item in selectList.taskEventTypeOptions"
              :key="item.value"
              :label="item.label"
              :value="item.label">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="监听器类型">
          <el-select v-model="form.listenerType" placeholder="请选择">
            <el-option
              v-for="item in selectList.listenerTypeOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="java类" v-if="form.listenerType == '1'">
          <el-input v-model="form.class"></el-input>
        </el-form-item>
        <el-form-item label="表达式" v-if="form.listenerType == '2'">
          <el-input v-model="form.expression"></el-input>
        </el-form-item>
        <el-form-item label="代理表达式" v-if="form.listenerType == '3'">
          <el-input v-model="form.delegateExpression"></el-input>
        </el-form-item>
      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button size="medium" @click="handleClickDeal('cancel')"> 取 消
        </el-button>
        <el-button size="medium" type="primary" @click="handleClickDeal('submit')">
          保 存
        </el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  export default {
    name: "task-detail",
    props: {
      postDetail: {
        type: Object,
        default: {
          show: false
        }
      }
    },
    data() {
      return {
        tableShow: false,
        form: {
          event: 'create',
          listenerType: '1',
          scriptType: '',
          expression: '',
          resource: '',
        },
        selectList: {
          listenerTypeOptions: [{value: '1', label: 'java类'}, {value: '2', label: '表达式'}, {value: '3', label: '代理表达式'}],
          taskEventTypeOptions: [{value: '1', label: 'create'}, {value: '2', label: 'assignment'}, {
            value: '3',
            label: 'complete'
          }, {value: '4', label: 'delete'}]
        },
      }
    },
    methods: {
      //清空表单
      reset() {
        this.form = {
          event: 'create',
          listenerType: '1',
          scriptType: '',
          expression: '',
          resource: '',
        }
      },
      handleClickDeal(type) {
        switch (type) {
          // 取消，关闭窗口
          case 'cancel':
            this.reset()
            this.tableShow = false
            break
          // 保存
          case 'submit':
            this.$emit('updateTaskTable', this.form, 2)
            this.tableShow = false
            break
          // 删除
          case 'delete':

            break
        }
      },
    },
    watch: {
      postDetail(value) {
        this.tableShow = value.show
      }
    }
  }
</script>

<style lang="scss" scoped>
  ::v-deep {
    .el-dialog {
      border-radius: 3px;
    }
    .el-dialog__body {
      padding: 30px;
    }

  }
</style>
